/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import business.TourBusiness;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
import model.PackageTour;

/**
 *
 * @author Administrator
 */
@ManagedBean
@RequestScoped
public class ListPackageTourCustomerBean {

    private TourBusiness tourBusiness = new TourBusiness();
    private List<Integer> pageIndex;
    private List<PackageTour> listPackageTour;
    private int typeID;
    private int pageID;

    public int getPageID() {
        return pageID;
    }

    public void setPageID(int pageID) {
        this.pageID = pageID;
    }

    public int getTypeID() {
        return typeID;
    }

    public void setTypeID(int typeID) {
        this.typeID = typeID;
    }

    public List<PackageTour> getListPackageTour() {
        return listPackageTour;
    }

    public void setListPackageTour(List<PackageTour> listPackageTour) {
        this.listPackageTour = listPackageTour;
    }

    public List<Integer> getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(List<Integer> pageIndex) {
        this.pageIndex = pageIndex;
    }

    /** Creates a new instance of ListPackageTourCustomerBean */
    public ListPackageTourCustomerBean() {
        if (FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("typeID") != null) {
            typeID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("typeID").toString());
            pageID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("pageID").toString());
        } else {
            pageID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("PageID").toString());
            typeID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("TypeID").toString());
        }
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        session.setAttribute("PageID", pageID);
        session.setAttribute("TypeID", typeID);
        int index = tourBusiness.getRowInListPackageTourByTypeID(typeID);
        pageIndex = new ArrayList<Integer>();
        if (index % 3 == 0) {
            for (int i = 1; i <= index / 3; i++) {
                pageIndex.add(i);
            }
        } else {
            for (int i = 1; i <= index / 3 + 1; i++) {
                pageIndex.add(i);
            }
        }
        listPackageTour = tourBusiness.listPackageTourByPage(typeID, pageID);
    }
}
